package com.lbb.simple.demo.adapter

import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions.bitmapTransform
import com.lbb.simple.demo.bean.Banner
import com.lbb.utils.DisplayUtil
import com.lbb.utils.recycler.BaseViewHolder
import com.lbb.utils.recycler.BaseViewModelAdapter
import jp.wasabeef.glide.transformations.RoundedCornersTransformation

class BannerAdapter : BaseViewModelAdapter<Banner>() {

    override fun onBindHolder(holder: BaseViewHolder, position: Int) {
        val imageView = holder.itemView as ImageView
        val margin = DisplayUtil.dp2px(10f)
        val margin2 = DisplayUtil.dp2px(5f)
        when (position) {
            0 -> {
                imageView.layoutParams = ViewGroup.LayoutParams(
                    DisplayUtil.getScreenWidth() - margin,
                    ViewGroup.LayoutParams.MATCH_PARENT
                )
               // imageView.setPadding(margin, 0, margin2, 0)
            }
            getItemSize() - 1 -> {
                imageView.layoutParams = ViewGroup.LayoutParams(
                    DisplayUtil.getScreenWidth() - margin,
                    ViewGroup.LayoutParams.MATCH_PARENT
                )
               // imageView.setPadding(margin2, 0, margin, 0)
            }
            else -> {
                imageView.layoutParams = ViewGroup.LayoutParams(
                    DisplayUtil.getScreenWidth() - margin * 2,
                    ViewGroup.LayoutParams.MATCH_PARENT
                )
              //  imageView.setPadding(margin2, 0, margin2, 0)
            }
        }
        list?.let {
            Glide.with(context).load(it[position].imgUrl).apply(
                bitmapTransform(
                    RoundedCornersTransformation(
                        DisplayUtil.dp2px(6f),
                        0,
                        RoundedCornersTransformation.CornerType.ALL
                    )
                )
            ).into(holder.itemView as ImageView)
        }
    }

    override fun getView(parent: ViewGroup): View {
        val imageView = ImageView(context)
        imageView.scaleType = ImageView.ScaleType.CENTER_CROP
        // imageView.setPadding(DisplayUtil.dp2px(16f),0,DisplayUtil.dp2px(16f),0,)
        return imageView
    }
}